Distance map-based warping of binary images

ABSTRACT

A method, including calculating a first distance matrix for a first binary image and a second distance matrix for a second binary image, and calculating a first gradient matrix for the first distance matrix and a second gradient matrix for the second distance matrix. Using the calculated distance and gradient matrices, a displacement matrix is calculated that defines a change in position between elements in the first distance matrix and corresponding elements in the second distance matrix. Outlier elements are identified including elements in the displacement matrix satisfying at least one predetermined criterion, and the identified outlier are replaced with calculated interpolated values.

FIELD OF THE INVENTION

This invention relates generally to digital image processing, andspecifically to calculating a non-rigid registration between two binaryimages.

BACKGROUND OF THE INVENTION

Image warping is the process of digitally manipulating a digital image(also referred to herein as an image) so that any shapes portrayed inthe image have been significantly distorted. Image warping may be usedfor correcting image distortion as well as for creative purposes (e.g.,morphing). Additionally, warping of binary (also known as bi-level)images can be used by computer vision applications such as OpticalCharacter Recognition (OCR), when comparing two digital images.

SUMMARY OF THE INVENTION

There is provided, in accordance with an embodiment of the presentinvention a method, including calculating a first distance matrix for afirst binary image and a second distance matrix for a second binaryimage, calculating a first gradient matrix for the first distance matrixand a second gradient matrix for the second distance matrix,calculating, using the first gradient matrix and a difference betweenthe first and the second distance matrices, a displacement matrix thatdefines a change in position between elements in the first distancematrix and corresponding elements in the second distance matrix,identifying outlier elements comprising elements in the displacementmatrix satisfying at least one predetermined criterion, and replacingthe identified outlier elements with calculated interpolated values.

There is also provided, in accordance with an embodiment of the presentinvention an apparatus, including a memory storing a first binary imageand a second binary image, and a processor configured to calculate afirst distance matrix for the first binary image and a second distancematrix for the second binary image, to calculate a first gradient matrixfor the first distance matrix and a second gradient matrix for thesecond distance matrix, to calculate, using the first gradient matrixand a difference between the first and the second distance matrices, adisplacement matrix that defines a change in position between elementsin the first distance matrix and corresponding elements in the seconddistance matrix, to identify outlier elements comprising elements in thedisplacement matrix satisfying at least one predetermined criterion, andto replace the identified outlier elements with calculated interpolatedvalues.

There is further provided, in accordance with an embodiment of thepresent invention a computer program product, the computer programproduct including a non-transitory computer readable storage mediumhaving computer readable program code embodied therewith, the computerreadable program code including computer readable program codeconfigured to calculate a first distance matrix for a first binary imageand a second distance matrix for a second binary image, computerreadable program code configured to calculate a first gradient matrixfor the first distance matrix and a second gradient matrix for thesecond distance matrix, computer readable program code configured tocalculate, using the first gradient matrix and a difference between thefirst and the second distance matrices, a displacement matrix thatdefines a change in position between elements in the first distancematrix and corresponding elements in the second distance matrix,computer readable program code configured to identify outlier elementscomprising elements in the displacement matrix satisfying at least onepredetermined criterion, and computer readable program code configuredto replace the identified outlier elements with calculated interpolatedvalues.

BRIEF DESCRIPTION OF THE DRAWINGS

The disclosure is herein described, by way of example only, withreference to the accompanying drawings, wherein:

FIG. 1 is a schematic pictorial illustration of a system configured tocalculate a displacement matrix that defines a non-rigid registrationbetween a first and a second binary image, in accordance with anembodiment of the present invention;

FIG. 2 is a flow diagram that schematically illustrates a method ofcalculating the displacement matrix, in accordance with an embodiment ofthe present invention;

FIGS. 3A 3B and 3C, referred to collectively as FIG. 3, are pictorialillustrations of an example first binary image and a first distancematrix for the first binary image, in accordance with an embodiment ofthe present invention;

FIGS. 4A, 4B and 4C, referred to collectively as FIG. 4, are pictorialillustrations of an example second binary image and a second distancematrix for the second binary image, in accordance with an embodiment ofthe present invention; and

FIG. 5 is a graph showing distance values of corresponding regions inthe first and the second distance matrices, in accordance with anembodiment of the present invention.

DETAILED DESCRIPTION OF EMBODIMENTS Overview

Image warping is typically performed by applying a geometrictransformation to a digital image. Given a digital image M and acontinuous deformation field h, a warped digital image S can be computedso that for each pixel v, S(v)=M(h(v)). Since h(v) does not necessarilycorrespond with a grid point, various interpolation techniques aretypically utilized in order to evaluate M(h(v)).

Analysis of a digital image may involve analyzing a distance map (alsoreferred to herein as a distance matrix) and/or a gradient map (alsoreferred to herein as a gradient matrix) of the digital image. Adistance map comprises a derived representation of the digital image,where each value in the distance map indicates a distance between acorresponding pixel in the digital image and a closest boundary pixel inthe digital image. For example, boundary pixels may comprise a contour(comprising contour pixels) of a digital image, in which case each valuein the distance map indicates a distance between a given pixel and itsclosest contour pixel. Similarly, a gradient map comprises a derivedrepresentation of a digital image, so that each value in the gradientmap indicates a direction (e.g., an angle) between a given pixel in thedigital image and its closest boundary pixel.

Embodiments of the present invention provide methods and systems fordistance map-based warping between a first and a second binary image byfinding a non-rigid registration between the two binary images. A binaryimage comprises a digital image that has only two possible values for agiven pixel. In some embodiments, contours are first identified for thefirst and the second binary images, and distance matrices are calculatedfor the two binary images, where the boundary pixels comprise theidentified contours. As described in detail hereinbelow, gradientmatrices may then be calculated for the distance matrices, and adisplacement matrix may then be calculated in order to define a changein position between corresponding pixels in the two binary images. Insome embodiments, any outlier elements in the displacement matrix areidentified and replaced with interpolated values, where the outlierelements comprise undesired regions in the binary images, as describedin detail hereinbelow.

Embodiments of the present invention provide an accurate level of imagewarping even when there are no predefined features for the two binaryimages, and when the two binary images are not overlapping one another.Additionally, any kind of transformation model (i.e., displacementmatrix) can be used to define the change in position between the twobinary images.

System Description

FIG. 1 is a schematic pictorial illustration of a system 20 configuredto calculate a displacement matrix 22 that defines a non-rigidregistration between a first binary image 24 and a second binary image26, in accordance with an embodiment of the present invention. System 20comprises a processor 28 coupled to a memory 30 via a bus 32.

As described in detail hereinbelow, processor 28 executes an imagewarping application 34 that is configured to calculate displacementmatrix 22. In operation, image warping application 34 is configured toconvert a first image 36 to first binary image 24, and to calculate afirst distance matrix 38 and a first gradient matrix 40 from the firstbinary image. Each element in the first distance matrix has acorresponding pixel in the first binary image, and each element in thefirst gradient matrix has a corresponding element in the first distancematrix.

Image warping application 34 is also configured to convert a secondimage 42 to second binary image 26, and to calculate a second distancematrix 44 and a second gradient matrix 46 from the second binary image.Image warping application 34 is also configured to calculatedisplacement matrix 22 using distance matrices 38 and 44, and gradientmatrices 40 and 46. Each element in the second distance matrix has acorresponding pixel in the second binary image, and each element in thesecond gradient matrix has a corresponding element in the seconddistance matrix.

Additionally, each pixel in the first binary image has a correspondingpixel in the second binary image, each element in the first distancematrix has a corresponding element in the second distance matrix, andeach element in the first gradient matrix has a corresponding element inthe second gradient matrix.

Processor 28 typically comprises a general-purpose computer configuredto carry out the functions described herein. Software operated by theprocessor may be downloaded to the memories in electronic form, over anetwork, for example, or it may be provided on non-transitory tangiblemedia, such as optical, magnetic or electronic memory media.Alternatively, some or all of the functions of the processor may becarried out by dedicated or programmable digital hardware components, orby using a combination of hardware and software elements.

As will be appreciated by one skilled in the art, aspects of the presentinvention may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present invention may take the formof an, entirely hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects that may allgenerally be referred to herein as a “circuit,” “module” or “system”.Furthermore, aspects of the present invention may take the form of acomputer program product embodied in one or more computer readablemedium(s) having computer readable program code embodied thereon.

Any combination of one or more computer readable medium(s) may beutilized. The computer readable medium may be a computer readable signalmedium or a computer readable storage medium. A computer readablestorage medium may be, for example, but not limited to, an electronic,magnetic, optical, electromagnetic, infrared, or semiconductor system,apparatus, or device, or any suitable combination of the foregoing. Morespecific examples (a non-exhaustive list) of the computer readablestorage medium would include the following: an electrical connectionhaving one or more wires, a portable computer diskette, a hard disk, arandom access memory (RAM), a read-only memory (ROM), an erasableprogrammable read-only memory (EPROM or Flash memory), an optical fiber,a portable compact disc read-only memory (CD-ROM), an optical storagedevice, a magnetic storage device, or any suitable combination of theforegoing. In the context of this document, a computer readable storagemedium may be any tangible medium that can contain, or store a programfor use by or in connection with an instruction execution system,apparatus, or device.

A computer readable signal medium may include a propagated data signalwith computer readable program code embodied therein, for example, inbaseband or as part of a carrier wave. Such a propagated signal may takeany of a variety of forms, including, but not limited to,electro-magnetic, optical, or any suitable combination thereof. Acomputer readable signal medium may be any computer readable medium thatis not a computer readable storage medium and that can communicate,propagate, or transport a program for use by or in connection with aninstruction execution system, apparatus, or device.

Program code embodied on a computer readable medium may be transmittedusing any appropriate medium, including but not limited to wireless,wireline, optical fiber cable, or any suitable combination of theforegoing.

Computer program code for carrying out operations for aspects of thepresent invention may be written in any combination of one or moreprogramming languages, including an object oriented programming languagesuch as Java, Smalltalk, C++ or the like and conventional proceduralprogramming languages, such as the “C” programming language or similarprogramming languages. The program code may execute entirely on theuser's computer, partly on the user's computer, as a stand-alonesoftware package, partly on the user's computer and partly on a remotecomputer or entirely on the remote computer or server. In the latterscenario, the remote computer may be connected to the user's computerthrough any type of network, including a local area network (LAN) or awide area network (WAN), or the connection may be made to an externalcomputer (for example, through the Internet using an Internet ServiceProvider).

Aspects of the present invention are described herein with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems) and computer program products according to, embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer program instructions. These computer program instructions maybe provided to a processor of a general purpose computer, specialpurpose computer, or other programmable data processing apparatus toproduce a machine, such that the instructions, which execute via theprocessor of the computer or other programmable data processingapparatus, create means for implementing the functions/acts specified inthe flowchart and/or block diagram block or blocks. These computerprogram instructions may also be stored in a computer readable mediumthat can direct a computer, other programmable data processingapparatus, or other devices to function in a particular manner, suchthat the instructions stored in the computer readable medium produce anarticle of manufacture including instructions which implement thefunction/act specified in the flowchart and/or block diagram block orblocks.

The computer program instructions may also be loaded onto a computer,other programmable data processing apparatus, or other devices to causea series of operational steps to be performed on the computer, otherprogrammable apparatus or other devices to produce a computerimplemented process such that the instructions which execute on thecomputer or other programmable apparatus provide processes forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks.

Calculating a Displacement Matrix

FIG. 2 is a flow diagram that schematically illustrates a method ofcalculating displacement matrix 22, in accordance with an embodiment ofthe present invention. FIG. 3A is a pictorial representation of firstbinary image 24, FIG. 3B is a pictorial representation of first binaryimage 24 with a contour 70, and FIG. 3C is a pictorial representation offirst distance matrix 38 for the first binary image, in accordance withan embodiment of the present invention.

FIG. 4A is a pictorial representation of second binary image 26, FIG. 4Bis a pictorial representation of second binary image 26 with a contour90, and FIG. 4C is a pictorial representation of second distance matrix44 for the second binary image, in accordance with an embodiment of thepresent invention. Images 24 and 26 are exemplary illustrations. FIG. 5is a graph 110 plotting first distance values 80 of a subset 82 of thefirst distance matrix and second distance values 100 of a correspondingsubset 102 of the second distance matrix, in accordance with anembodiment of the present invention.

In a transformation step 50, using digital image processing techniquesknown in the art, processor 28 converts first image 36 to first binaryimage 24, and converts second image 42 to second binary image 26. In afirst identification step 52, processor 28 identifies a first contour 70for first binary image 24, representing a first example character “M”,and identifies a second contour 90 for second binary image 26representing a second example character “M”.

In a first calculation step 54, processor 28 calculates first distancematrix 38 for each pixel of first binary image 24 and second distancematrix 44 for each pixel of second binary image 26. Processor 28 cancalculate the first and the second distance matrices using the formula

$\begin{matrix}{{T_{p}(q)} = {\inf\limits_{p \in P}{{p - q}}_{L^{2}}}} & (1)\end{matrix}$where P comprises a given contour (i.e., contour 70 or contour 90), qcomprises a given pixel (i.e., in the first or the second binary image),and L comprises a Euclidean distance.

Therefore, in the example shown in FIG. 3, processor 28 calculates avalue for each element of first distance matrix 38 that indicates adistance between a pixel in the first binary image and a closest pointto the pixel on contour 70. Likewise, in the example shown in FIG. 4,processor 28 calculates a value for each element of second distancematrix 44 that indicates a distance between a pixel in the second binaryimage and a closest point to the pixel on contour 90.

FIGS. 3C and 4C present the first and the second distance maps asgrayscale images, where the values in the distance matrices arepresented as intensities (i.e., lighter or darker shades of gray). InFIG. 3C, the intensity of a given element of first distance matrix 38 isdirectly proportional to a distance between a corresponding pixel infirst binary image 24 and contour 70. For example, FIG. 3C shows values80 for a one-dimensional subset 82 of first distance matrix 38, whereeach given value 80 comprises a distance to contour 70 that can bepresented as an intensity in FIG. 3C. Likewise, in FIG. 4C, theintensity of a given element of second distance matrix 44 is directlyproportional to a distance between a corresponding pixel in secondbinary image 26 and contour 90. Black pixels in FIG. 3C indicate pixelseither on or within contour 70, and black pixels in FIG. 4C indicatepixels either on or within contour 90.

In FIG. 3C, a given value 80 that is positive (i.e. >0) indicates adistance between corresponding pixel in binary image 24 and a closestpoint on contour 70, where the corresponding pixel is positioned outsidecontour 70. A given value 80 that equals zero indicates a correspondingpixel in binary image 24 that is positioned on contour 70. A given value80 that is negative (i.e. <0) indicates a distance between correspondingpixel in binary image 24 and a closest point on contour 70, where thecorresponding pixel is positioned within contour 70.

Likewise, in FIG. 4C, a given value 100 that is positive (i.e. >0)indicates a distance between corresponding pixel in binary image 26 anda closest point on contour 90, where the corresponding pixel ispositioned outside contour 90. A given value 100 that equals zeroindicates a corresponding pixel in binary image 26 that is positioned oncontour 90. A given value 100 that is negative (i.e. <0) indicates adistance between corresponding pixel in binary image 26 and a closestpoint on contour 90, where the corresponding pixel is positioned withincontour 90.

In a second calculation step 56, processor 28 calculates first gradientmatrix 40, also termed I1, for first binary image 24, and secondgradient matrix 46, also termed I2, for second binary image 26. Eachelement in the first gradient matrix comprises a horizontal X-axiscomponent and a vertical Y-axis component that when combined indicate anangle between a pixel in first binary image 24 and its closest point oncontour 70. Likewise, each element in the second gradient matrixcomprises a horizontal X-axis component and a vertical Y-axis componentthat when combined indicate an angle between a pixel in second binaryimage 26 and its closest point on contour 90.

In a third calculation step 58, processor 28 calculates displacementmatrix 22 using first distance matrix 38, second distance matrix 44 andfirst gradient matrix 40. Displacement matrix 22 has an X-axis componentu and a Y-axis component v that can be initially calculated as follows:

$\begin{matrix}{{u = {- \frac{I\; 1_{x}I_{t}}{\sqrt[2]{{I\; 1_{x}^{2}} - {I\; 1_{y}^{2}}}}}},} & (2) \\{v = {- \frac{I\; 1_{y}I_{t}}{\sqrt[2]{{I\; 1_{x}^{2}} - {I\; 1_{y}^{2}}}}}} & (3)\end{matrix}$

In Equations (2) and (3), I_(t) represents a difference between I1 andI2. For example, if for a given pixel (x,y) I1(x,y) is “3” and thecorresponding value in the second distance matrix, I2(x,y) is “5”, thenI_(t)(x,y) is “2”. For a given pixel (x,y) in the first binary image,I1_(x) represents a partial derivative along the X-axis, and I1_(y)represents a partial derivative along the Y-axis (i.e., I1_(x) andI1_(y) represent respective X-axis and Y-axis components of the firstgradient matrix).

Using Equations (2) and (3) processor 28 can calculate (u(x,y), v(x,y))for every pixel (x,y) in first binary image 36, thereby generatingdisplacement matrix 22. The processor may also calculate a polynomialtransformation between source points (x_(i), y_(i)) and destinationpoints (x_(i)+u(x_(i), y_(i)), y_(i)+v(x_(i), y_(i)) using displacementmatrix 22.

As described supra, each element in displacement matrix 22 typicallycomprises a first value indicating a displacement along the X-axis(i.e., “u”), and a second value indicating a displacement along theY-axis (i.e, “v”). For example, in FIGS. 3C and 4C, the fourth value 80in subset 82 is “3”, and the fourth value 100 in subset 102 is “1”.Assuming I1_(y)=0, then I1_(x)=3, and I_(t)=2. Therefore, applyingEquations (2) and (3) to calculate the transformation matrix element (u,v) for the corresponding pixel in binary image 24 results in u=2 andv=0.

In a second identification step 60, processor 28 identifies any“outlier” elements in displacement matrix 22. An outlier elementcomprises an element in displacement matrix 22, where a calculated anglebetween an element in the first gradient matrix and a correspondingelement in the second gradient matrix is outside specified predeterminedcriteria. For example, processor 28 can set the criteria as (a) ∇I1²>0,(b) ∇I2²>0, and (c) ∇I1·∇I2>0. The first two criteria eliminate anyinfluence of regions with zero spatial gradients, and the thirdcriterion eliminates the influence of a joint region where the spatialgradients of the first and the second distance matrices are related by agiven angle. In the third criterion, ∇I1·∇I2>0 indicates that an anglebetween an element in the first gradient matrix and a correspondingelement in the second gradient matrix needs to be less than 90° tosatisfy the criterion.

In some embodiments, processor 28 can specify the criteria for outlierand non-outlier elements based on a type of application currentlyexecuting on a processor. For example, for an OCR application, processor28 can set criterion (c) to ∇I1·∇I2>0, and for a facial recognitionapplication, processor 28 can set criterion (c) to ∇I1·∇I2>0.3, therebyindicating that an angle between an element in the first gradient matrixand a corresponding element in the second gradient matrix needs to beless than 60° to satisfy the criterion. Alternatively processor 28 canset any number of criteria based on any combination of the first and thesecond gradient maps and the first and the second distance maps.

Graph 110 in FIG. 5 plots distance (i.e., intensity) vs. X-axislocations (i.e., in the first and the second distance maps) for values80 of subset 82 and values 100 of subset 102. As indicated by values 80and 100, subset 102 comprises subset 82 shifted two pixels to the right.Graph 110 presents subsets 82 and 102 as aligned (i.e., have similarslopes) in regions 112 and 116, and as not aligned in region 114. Inembodiments of the present invention, values 102 and 104 within region114 reference the outlier elements described supra.

Finally, in a replacement step 62, processor 28 calculates interpolatedvalues for any identified outlier elements of the displacement matrix,and replaces the identified outlier elements with the calculatedinterpolated values. To calculate the interpolated values, Processor 28can use calculations that are known in the art, including a model-basedinterpolation, a free-form interpolation and a polynomial interpolation.In some embodiments, processor 28 can calculate the interpolated valuesbased on non-outlier elements (i.e., elements meeting the specifiedcriteria) in the displacement matrix in proximity to the outlierelements.

The flowchart and block diagrams in the figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). It should also be notedthat, in some alternative implementations, the functions noted in theblock may occur out of the order noted in the figures. For example, twoblocks shown in succession may, in fact, be executed substantiallyconcurrently, or the blocks may sometimes be executed in the reverseorder, depending upon the functionality involved. It will also be notedthat each block of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

It will be appreciated that the embodiments described above are cited byway of example, and that the present invention is not limited to whathas been particularly shown and described hereinabove. Rather, the scopeof the present invention includes both combinations and subcombinationsof the various features described hereinabove, as well as variations andmodifications thereof which would occur to persons skilled in the artupon reading the foregoing description and which are not disclosed inthe prior art.

The invention claimed is:
 1. A method, comprising: calculating a firstdistance matrix for a first binary image and a second distance matrixfor a second binary image; calculating a first gradient matrix for thefirst distance matrix and a second gradient matrix for the seconddistance matrix; calculating, using the first gradient matrix and adifference between the first and the second distance matrices, adisplacement matrix that defines a change in position between elementsin the first distance matrix and corresponding elements in the seconddistance matrix; identifying outlier elements comprising elements in thedisplacement matrix satisfying at least one predetermined criterion;replacing the identified outlier elements with calculated interpolatedvalues and wherein the predetermined criterion comprises an anglebetween a corresponding first gradient matrix element and acorresponding second gradient matrix element exceeding a specifiedthreshold.
 2. The method according to claim 1, and comprising convertinga first image to the first binary image, and converting a second imageto the second binary image prior to calculating the first and the seconddistance matrices.
 3. The method according to claim 1 and comprisingcalculating a first contour for the first binary image, and calculatinga second contour for the second binary image prior to calculating thefirst and the second distance matrices.
 4. The method according to claim3, wherein each element in the first distance matrix has a correspondingpixel in the first binary image, and indicates a distance between thecorresponding pixel and a closest point on the first contour.
 5. Themethod according to claim 4, wherein each element in the first gradientmatrix has a corresponding element in the first distance matrix, andindicates an angle towards the closest point on the first contour. 6.The method according to claim 3, wherein each element in the seconddistance matrix has a corresponding pixel in the second binary image,and indicates a distance between the corresponding pixel and a closestpoint on the second contour.
 7. The method according to claim 6, whereineach element in the second gradient matrix has a corresponding elementin the second distance matrix, and indicates an angle towards theclosest point on the second contour.
 8. The method according to claim 1,wherein the interpolated values are calculated using calculationsselected from a list consisting of a model-based interpolation, afree-form interpolation and a polynomial interpolation.
 9. The methodaccording to claim 1, wherein the interpolated values are calculatedbased on non-outlier elements in the displacement matrix in proximity tothe outlier elements.
 10. The apparatus according to claim 1, whereineach element in the second distance matrix has a corresponding pixel inthe second binary image, and indicates a distance between thecorresponding pixel and a closest point on the second contour.
 11. Theapparatus according to claim 10, wherein each element in the secondgradient matrix has a corresponding element in the second distancematrix, and indicates an angle towards the closest point on the secondcontour.
 12. The method according to claim 1, wherein the processor isconfigured to calculate the interpolated values based on non-outlierelements in the displacement matrix in proximity to the outlierelements.
 13. An apparatus, comprising: a memory storing a first binaryimage and a second binary image; and a processor configured to calculatea first distance matrix for the first binary image and a second distancematrix for the second binary image, to calculate a first gradient matrixfor the first distance matrix and a second gradient matrix for thesecond distance matrix, to calculate, using the first gradient matrixand a difference between the first and the second distance matrices, adisplacement matrix that defines a change in position between elementsin the first distance matrix and corresponding elements in the seconddistance matrix, to identify outlier elements comprising elements in thedisplacement matrix satisfying at least one predetermined criterion, andto replace the identified outlier elements with calculated interpolatedvalues, wherein the predetermined criterion comprises an angle between acorresponding first gradient matrix element and a corresponding secondgradient matrix element exceeding a specified threshold.
 14. Theapparatus according to claim 13, wherein the processor is configured toconvert a first image to the first binary image, and to convert a secondimage to the second binary image prior to calculating the first and thesecond distance matrices.
 15. The apparatus according to claim 13,wherein the processor is configured to calculate a first contour for thefirst binary image, and to calculate a second contour for the secondbinary image prior to calculating the first and the second distancematrices.
 16. The apparatus according to claim 15, wherein each elementin the first distance matrix has a corresponding pixel in the firstbinary image, and indicates a distance between the corresponding pixeland a closest point on the first contour.
 17. The apparatus according toclaim 16, wherein each element in the first gradient matrix has acorresponding element in the first distance matrix, and indicates anangle towards the closest point on the first contour.
 18. The apparatusaccording to claim 13, wherein the processor is configured to calculatethe interpolated values by using calculations selected from a listconsisting of a model-based interpolation, a free-form interpolation anda polynomial interpolation.
 19. A computer program product, the computerprogram product comprising: a non-transitory computer readable storagemedium having computer readable program code embodied therewith, thecomputer readable program code comprising: computer readable programcode configured to calculate a first distance matrix for a first binaryimage and a second distance matrix for a second binary image; computerreadable program code configured to calculate a first gradient matrixfor the first distance matrix and a second gradient matrix for thesecond distance matrix; computer readable program code configured tocalculate, using the first gradient matrix and a difference between thefirst and the second distance matrices, a displacement matrix thatdefines a change in position between elements in the first distancematrix and corresponding elements in the second distance matrix;computer readable program code configured to identify outlier elementscomprising elements in the displacement matrix satisfying at least onepredetermined criterion; and computer readable program code configuredto replace the identified outlier elements with calculated interpolatedvalues and wherein the predetermined criterion comprises an anglebetween a corresponding first gradient matrix element and acorresponding second gradient matrix element exceeding a specifiedthreshold.